package com.learn.hd.swap;

import java.util.Arrays;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description 交换排序----冒泡排序
 * @date 2019/7/15
 */
public class bubbleSort {

    public static void main(String[] args) {

        int[] array = new int[]{ 4, 6, 1, 9, 12, 45, 19, 100, 7};

        for (int i = 0; i < array.length ; i++) {

            for (int j = array.length-1; j > i ; j--) {
                if (array[j] < array[j-1]) {
                    swap(array, j, j-1);
                }
            }
        }

        System.out.println(Arrays.toString(array));
    }

    private static void swap(int[] array, int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}
